package com.bnlr.lrparking.appui.publish.adapter;

import android.support.annotation.Nullable;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.bnlr.lrparking.R;
import com.bnlr.lrparking.model.MyPublishBean;
import com.bnlr.lrparking.util.CommonUtil;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */

public class SelectPublishAdapter extends BaseQuickAdapter<MyPublishBean.DataBean,BaseViewHolder>{
    private List<String> selectId;
    public SelectPublishAdapter(@Nullable List<MyPublishBean.DataBean> data) {
        super(R.layout.item_select_publish_layout,data);
        selectId = new ArrayList<>();
    }

    @Override
    protected void convert(final BaseViewHolder helper, final MyPublishBean.DataBean item) {
        selectId.clear();
        helper.setText(R.id.item_select_publish_time,"发布于 "+ CommonUtil.timeGap(item.getCreateTime()));
        helper.setText(R.id.item_select_publish_title,item.getTitle());
        Glide.with(mContext).load(item.getPhotoUrl()).into((ImageView) helper.getView(R.id.item_select_publish_iv));
        final CheckBox checkBox = helper.getView(R.id.cb_publish_item);
        checkBox.setChecked(false);
        switch (item.getAuditStatus()) {
            // 审核状态 0正常，1下线，2待审核，3审核不通过，4用户删除
            case 0:
                helper.setText(R.id.item_select_publish_status,"显示中");
                break;
            case 2:
                helper.setText(R.id.item_select_publish_status,"正在审核");
                break;
            default:
                break;
        }
        switch (item.getType()) {
            case 10:
                helper.setText(R.id.tv_select_publish_type,"在租");
                break;
            case 11:
                helper.setText(R.id.tv_select_publish_type,"在售");
                break;
            default:
                break;

        }
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    selectId.add(item.getId()+"");
                } else {
                    selectId.remove(item.getId()+"");
                }
            }
        });

    }
    public List<String> getSelectId () {
        return selectId;
    }

}
